import { nextTick, ref } from "vue";
const headerTop = ref<string>("0px");
const sheight = ref<string>("0px");
export const useSelfHeight = (hasMenue: boolean = false) => {
  return new Promise<any>((resolve, reject) => {
    try {
      nextTick(() => {
        setTimeout(() => {
          if (hasMenue == true) {
            let t = document.querySelector(".van-nav-bar") as HTMLDivElement;
            let d = document.querySelector(".van-tabs__nav") as HTMLDivElement;
            // let vt = document.querySelector(".van-tabbar") as HTMLDivElement;

            if (d) {
              let w = window.innerHeight;
              headerTop.value = t.offsetHeight + "px";
              sheight.value = w - t.offsetHeight - d.offsetHeight - 0 + "px";
              resolve({
                headerTop: headerTop.value,
                sheight: sheight.value,
              });
              return;
            }
            // if (vt) {
            //     let w = window.innerHeight;
            //     headerTop.value = t.offsetHeight + "px";
            //     sheight.value = w - t.offsetHeight - vt.offsetHeight + "px";
            //     resolve({
            //         headerTop: headerTop.value,
            //         sheight: sheight.value
            //     })
            //     return
            // }
            let s = document.querySelector(
              ".van-dropdown-menu"
            ) as HTMLDivElement;
            if (s) {
              let w = window.innerHeight;
              headerTop.value = t.offsetHeight + "px";
              sheight.value = w - t.offsetHeight - s.offsetHeight + "px";
              resolve({
                headerTop: headerTop.value,
                sheight: sheight.value,
              });
              return;
            }
          } else {
            let t = document.querySelector(".van-nav-bar") as HTMLDivElement;
            let w = window.innerHeight;
            headerTop.value = t.offsetHeight + "px";
            sheight.value = w - t.offsetHeight + "px";
            resolve({
              headerTop: headerTop.value,
              sheight: sheight.value,
            });
          }
        }, 40);
      });
    } catch (error) {
      reject(error);
    }
  });
};
